package com.myapp.common.bean;

import com.myapp.common.exception.SysException;
import com.myapp.common.msg.ErrorMeta;
import com.myapp.common.msg.Errors;
import com.myapp.common.msg.MsgInfo;

/**
 * 通用返回结果
 */
public class ResultBean extends ResultSupport<Integer, Object> {

	private static final ErrorMeta SUCEESS = Errors.SUCCESS;

	public ResultBean() {
		this.setCode(SUCEESS.getCode());
		this.setMsg(SUCEESS.getMsg());
	}

	public ResultBean(SysException e) {
		MsgInfo<Integer> msgInfo = e.getMsgInfo();
		this.setCode(msgInfo.getCode());
		this.setMsg(msgInfo.getMsg());
	}

	public static ResultBean success() {
		return new ResultBean();
	}

	public static ResultBean success(String msg) {
		ResultBean bean = success();
		bean.setMsg(msg);
		return bean;
	}

	public static ResultBean successData(Object data) {
		ResultBean bean = success();
		bean.setData(data);
		return bean;
	}

	public static ResultBean successData(String msg, Object data) {
		ResultBean bean = success();
		bean.setMsg(msg);
		bean.setData(data);
		return bean;
	}

	public static ResultBean error(Integer code, String msg) {
		ResultBean bean = new ResultBean();
		bean.setCode(code);
		bean.setMsg(msg);
		return bean;
	}

	public static ResultBean error(MsgInfo<Integer> msgInfo) {
		return error(msgInfo.getCode(), msgInfo.getMsg());
	}

	public static ResultBean error(SysException e) {
		return error(e.getMsgInfo());
	}

	public String getMsg() {
		return this.fatchMsg();
	}

	public Object getData() {
		return this.fatchData();
	}

	public Integer getCode() {
		return this.fatchCode();
	}

}
